import Vue from "vue";
import VueRouter from "vue-router";
import {
  Loading
} from 'element-ui';

Vue.use(VueRouter);
const router = new VueRouter({
  routes: [{
      path: "/",
      redirect: "/mainPage",
    }, {
      path: "/mainPage",
      name: "mainPage",
      meta: {
        icon: "mainPage",
        title: "主页"
      },
      // meta: { requiresAuth: true },  // 路由元数据信息
      component: () =>
        import("../views/mainPage/mainPage.vue")
    },
    {
      path: "/mession",
      name: "mission",
      meta: {
        icon: "mySession",
        title: "我的任务"
      },
      // meta: { requiresAuth: true },  // 路由元数据信息
      component: () =>
        import("../views/missionCenter/myMission.vue")
    }, {
      path: "/query/missionQuery",
      name: "missionQuery",
      meta: {
        icon: "missionQuery",
        title: "任务查询"
      },
      // meta: { requiresAuth: true },  // 路由元数据信息
      component: () =>
        import("../views/query/missionQuery.vue")
    }, {
      path: "/query/query",
      name: "query",
      meta: {
        icon: "query",
        title: "综合查询"
      },
      // meta: { requiresAuth: true },  // 路由元数据信息
      component: () =>
        import("../views/query/query.vue")
    },
    {
      path: "/case",
      name: "case",
      meta: {
        icon: "case",
        title: "案件中心"
      },
      component: () =>
        import("../views/caseCenter/caseCenter.vue")
    },
    {
      path: "/case/regist",
      name: "regist",
      meta: {
        icon: "regist",
        title: "报案登记查询"
      },
      component: () =>
        import("../views/caseCenter/regist.vue")
    }, {
      path: "/case/reportRegist",
      name: "reportRegist",
      meta: {
        icon: "reportRegist",
        title: "报案登记"
      },
      component: () =>
        import("../views/caseCenter/reportRegist.vue")
    }, {
      path: "/process",
      name: "process",
      meta: {
        icon: "process",
        title: "流程图"
      },
      component: () =>
        import("../views/process/process.vue")
    }, {
      path: "/redirect/:path*",
      hidden: true,
      component: {
        beforeCreate() {
          this.$router.replace({
            path: "/" + (this.$route.params.path ? this.$route.params.path : ""),
            query: this.$route.query
          });
        },
        render: function (h) {
          return h(); // avoid warning message
        }
      }
    },
  ],
  sampleRoutes: [{
      path: "/mession",
      name: "mission",
      meta: {
        icon: "mySession",
        title: "我的任务"
      },
      // meta: { requiresAuth: true },  // 路由元数据信息
      component: () =>
        import("../views/missionCenter/myMission.vue")
    },
    // {
    //     path: "/redirect/:path*",
    //     hidden: true,
    //     component: {
    //         beforeCreate() {
    //             this.$router.replace({
    //                 path: "/" + (this.$route.params.path ? this.$route.params.path : ""),
    //                 query: this.$route.query
    //             });
    //         },
    //         render: function(h) {
    //             return h(); // avoid warning message
    //         }
    //     }
    // }, {
    //     path: "/user",
    //     name: "user",
    //     meta: {
    //         icon: "love",
    //         title: "我的关注"
    //     },
    //     component: () =>
    //         import ("../views/saa/user")
    // },
    // {
    //     path: "/role",
    //     name: "role",
    //     meta: {
    //         icon: "transfer",
    //         title: "平级移交"
    //     },
    //     component: () =>
    //         import ("../views/saa/role/index")
    // },
    // {
    //     path: "/organization",
    //     name: "organization",
    //     meta: {
    //         icon: "taskPool",
    //         title: "任务池"
    //     },
    //     component: () =>
    //         import ("../views/saa/organization")
    // }
  ],
});

// var routerLoading = null;

/**
 * 导航守卫
 */
router.beforeEach((to, from, next) => {
  // 跳转时显示加载动画，进度条等
  // routerLoading = Loading.service({
  //   lock: true,
  //   text: '跳转中...',
  // })
  // 权限验证，页面有未保存数据跳转等情况的处理
  next(); // 确保要调用 next 方法，否则钩子就不会被 resolved。
});

router.afterEach(() => {
  // 跳转完成隐藏加载动画，进度条等，成功跳转后的一些处理
  // if(routerLoading){
  //   routerLoading.close()
  // }
});

export default router;
